﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Security.Cryptography;
using UnityEngine;
using UnityEngine.Animations;

public class InputManager : MonoBehaviour
{
    public string path= "New Input Data";
    static InputData inputData;
    public static  bool activeSetKey = false;
    static  Action<KeyCode> setKey;
    private void Awake()
    {
        inputData = Resources.Load<InputData>(path);
        if (inputData == null)
        {
            throw new Exception("inputData:无法加载");
        }
    }
    public void OnGUI()
    {
        if (!activeSetKey)
            return;
        Event e = Event.current;
        if (e.isKey&&setKey!=null)
        {
            KeyCode key = e.keyCode;
            Debug.Log(key);
            setKey(key);
            setKey = null;
            activeSetKey = false;
        }

    }

    private void Update()
    {
        inputData.AcceptInput();
    }

    public static void StartSetKey(Action<KeyCode> key)
    {
        setKey = key;
        activeSetKey = true;
    }

    public static float GetAxis(string name)
    {
        return inputData.Axis(name);
    }
    public static bool GetKeyDown(string name)
    {
        return inputData.GetKeyDown(name);
    }
    public static float GetValueKey(string name)
    {
        return inputData.GetValue(name);
    }
    public static void SetKey(string name,KeyCode key)
    {
        inputData.SetKey(name,key);
    }
    public static void SetValueKey(string name,KeyCode key)
    {
        inputData.SetValueKey(name,key);
    }
    public static void SetAxisKey(string name,KeyCode a,KeyCode b)
    {
        inputData.SetAxisKey(name,a,b);
    }
}
